import time
import requests
import unittest

class MeetAPITest(unittest.TestCase):
    s = None
    @classmethod
    def setUpClass(cls):
        cls.s = requests.Session()
        url = "http://118.121.200.162:8085/loginCheck.do"
        Data = {
            "userID": "mjj",
            "password": "123456"
        }
        res = cls.s.post(url, data=Data)
        assert 200 == res.status_code

    def test_getmessage(self):
        url = "http://118.121.200.162:8085/message/getMessageList"

        myparam = {
            "page": 1
        }
        res = self.s.get(url, params=myparam)
        self.assertEqual(200, res.status_code)
        self.assertIn("场馆怎么预约", res.text)
        print(res.text)

    def test_sendmessage(self):
        url = "http://118.121.200.162:8085/sendMessage"
        now = time.localtime()
        TIME = time.strftime("%Y%m%d%H%M%S", now)
        mydata = {
            "userID": "mjj",
            "content": "明俊杰的留言-" + TIME
        }
        res = self.s.post(url, data=mydata)
        self.assertEqual(200, res.status_code)

    def test_findUserList(self):
        url = "http://118.121.200.162:8085/message/findUserList"
        myparam = {
            "page": 1
        }
        res = self.s.get(url, params=myparam)
        self.assertEqual(200, res.status_code)
        self.assertIn("mjj", res.text)
        print(res.text)

    def test_delMessage(self):
        url = "http://118.121.200.162:8085/delMessage.do"
        mydata = {
            "messageID": "32819"
        }
        res = self.s.post(url, data=mydata)
        self.assertEqual(200, res.status_code)
        self.assertIsNot("32819", res.text)
        print(res.text)

if __name__ == "__main__":
    unittest.main()